<template>
  <div class="mouse-tracker">
    <div class="tracker-header">
      <h2>🖱️ 智能鼠标位置监听器</h2>
      <p class="subtitle">响应式数据 + 事件监听 + 计算属性实战演示</p>
    </div>
    
    <div class="tracker-body">
      <div class="position-display">
        <div class="position-grid">
          <div class="position-card x-position">
            <div class="position-icon">↔️</div>
            <div class="position-value">{{ mouseX }}</div>
            <div class="position-label">X 坐标</div>
            <div class="position-bar">
              <div class="position-fill" :style="{ width: xPercentage + '%' }"></div>
            </div>
          </div>
          
          <div class="position-card y-position">
            <div class="position-icon">↕️</div>
            <div class="position-value">{{ mouseY }}</div>
            <div class="position-label">Y 坐标</div>
            <div class="position-bar">
              <div class="position-fill" :style="{ height: yPercentage + '%' }"></div>
            </div>
          </div>
        </div>
        
        <div class="position-summary">
          <div class="summary-item">
            <span class="summary-icon">📍</span>
            <span>当前位置: ({{ mouseX }}, {{ mouseY }})</span>
          </div>
          <div class="summary-item">
            <span class="summary-icon">🖥️</span>
            <span>屏幕尺寸: {{ screenWidth }} × {{ screenHeight }}</span>
          </div>
          <div class="summary-item">
            <span class="summary-icon">📊</span>
            <span>相对位置: {{ xPercentage.toFixed(1) }}% × {{ yPercentage.toFixed(1) }}%</span>
          </div>
        </div>
      </div>
      
      <div class="tracking-area" @mousemove="handleMouseMove" @mouseenter="handleMouseEnter" @mouseleave="handleMouseLeave">
        <div class="area-header">
          <h3>🎯 鼠标跟踪区域</h3>
          <div class="area-status" :class="{ active: isTracking }">
            {{ isTracking ? '🟢 正在跟踪' : '🔴 未在区域内' }}
          </div>
        </div>
        
        <div class="mouse-cursor" v-if="isTracking" :style="cursorStyle">
          <div class="cursor-dot"></div>
          <div class="cursor-ring"></div>
        </div>
        
        <div class="area-grid">
          <div class="grid-lines horizontal"></div>
          <div class="grid-lines vertical"></div>
          <div class="grid-center"></div>
        </div>
        
        <div class="position-markers" v-if="isTracking">
          <div class="marker-x" :style="{ top: markerXPosition + 'px' }">
            <div class="marker-line"></div>
            <div class="marker-label">X: {{ mouseX }}</div>
          </div>
          <div class="marker-y" :style="{ left: markerYPosition + 'px' }">
            <div class="marker-line"></div>
            <div class="marker-label">Y: {{ mouseY }}</div>
          </div>
        </div>
        
        <div class="tracking-info" v-if="isTracking">
          <div class="info-item">
            <span class="info-label">区域位置:</span>
            <span class="info-value">({{ relativeX }}, {{ relativeY }})</span>
          </div>
          <div class="info-item">
            <span class="info-label">距离中心:</span>
            <span class="info-value">{{ distanceFromCenter.toFixed(0) }}px</span>
          </div>
          <div class="info-item">
            <span class="info-label">象限:</span>
            <span class="info-value">{{ currentQuadrant }}</span>
          </div>
        </div>
      </div>
      
      <div class="history-section">
        <div class="history-header">
          <h4>📈 位置历史轨迹</h4>
          <div class="history-controls">
            <button @click="clearHistory" class="clear-btn">🗑️ 清空</button>
            <button @click="toggleRecording" class="record-btn" :class="{ recording: isRecording }">
              {{ isRecording ? '⏸️ 暂停' : '▶️ 记录' }}
            </button>
          </div>
        </div>
        
        <div class="history-canvas">
          <div class="canvas-grid">
            <div 
              v-for="(point, index) in positionHistory" 
              :key="index"
              class="history-point"
              :style="{ 
                left: point.x + 'px', 
                top: point.y + 'px',
                opacity: point.opacity
              }"
              :title="`位置: (${point.x}, ${point.y}) - ${point.time}`"
            >
              <div class="point-dot"></div>
            </div>
            <div v-if="positionHistory.length === 0" class="empty-history">
              <div class="empty-icon">📭</div>
              <div class="empty-text">暂无历史轨迹</div>
            </div>
          </div>
        </div>
        
        <div class="history-stats">
          <div class="stats-item">
            <span class="stats-label">记录点数:</span>
            <span class="stats-value">{{ positionHistory.length }}</span>
          </div>
          <div class="stats-item">
            <span class="stats-label">平均X:</span>
            <span class="stats-value">{{ averagePosition.x.toFixed(0) }}</span>
          </div>
          <div class="stats-item">
            <span class="stats-label">平均Y:</span>
            <span class="stats-value">{{ averagePosition.y.toFixed(0) }}</span>
          </div>
          <div class="stats-item">
            <span class="stats-label">移动距离:</span>
            <span class="stats-value">{{ totalDistance.toFixed(0) }}px</span>
          </div>
        </div>
      </div>
      
      <div class="analysis-section">
        <h4>📊 移动分析</h4>
        <div class="analysis-grid">
          <div class="analysis-card movement-pattern">
            <h5>🔄 移动模式</h5>
            <div class="pattern-item">
              <span class="pattern-label">主要方向:</span>
              <span class="pattern-value">{{ movementPattern.direction }}</span>
            </div>
            <div class="pattern-item">
              <span class="pattern-label">移动速度:</span>
              <span class="pattern-value">{{ movementPattern.speed }}</span>
            </div>
            <div class="pattern-item">
              <span class="pattern-label">活跃程度:</span>
              <span class="pattern-value">{{ movementPattern.activity }}</span>
            </div>
          </div>
          
          <div class="analysis-card quadrant-stats">
            <h5>📍 象限统计</h5>
            <div class="quadrant-item" v-for="(count, quadrant) in quadrantStats" :key="quadrant">
              <span class="quadrant-label">{{ quadrant }}:</span>
              <div class="quadrant-bar">
                <div class="quadrant-fill" :style="{ width: getQuadrantPercentage(count) + '%' }"></div>
              </div>
              <span class="quadrant-count">{{ count }}</span>
            </div>
          </div>
          
          <div class="analysis-card speed-analysis">
            <h5>⚡ 速度分析</h5>
            <div class="speed-item">
              <span class="speed-label">当前速度:</span>
              <span class="speed-value">{{ currentSpeed.toFixed(1) }} px/s</span>
            </div>
            <div class="speed-item">
              <span class="speed-label">平均速度:</span>
              <span class="speed-value">{{ averageSpeed.toFixed(1) }} px/s</span>
            </div>
            <div class="speed-item">
              <span class="speed-label">最大速度:</span>
              <span class="speed-value">{{ maxSpeed.toFixed(1) }} px/s</span>
            </div>
          </div>
        </div>
      </div>
      
      <div class="controls-section">
        <div class="controls-grid">
          <div class="control-group">
            <h5>🎨 显示选项</h5>
            <div class="control-item">
              <label>
                <input type="checkbox" v-model="showCursor" @change="toggleShowCursor">
                显示鼠标光标
              </label>
            </div>
            <div class="control-item">
              <label>
                <input type="checkbox" v-model="showMarkers" @change="toggleShowMarkers">
                显示位置标记
              </label>
            </div>
            <div class="control-item">
              <label>
                <input type="checkbox" v-model="showGrid" @change="toggleShowGrid">
                显示网格
              </label>
            </div>
          </div>
          
          <div class="control-group">
            <h5>⚙️ 跟踪设置</h5>
            <div class="control-item">
              <label>
                采样间隔:
                <select v-model="sampleInterval" @change="updateSampleInterval">
                  <option value="50">50ms (高频率)</option>
                  <option value="100">100ms (标准)</option>
                  <option value="200">200ms (低频率)</option>
                </select>
              </label>
            </div>
            <div class="control-item">
              <label>
                历史记录上限:
                <input 
                  type="number" 
                  v-model.number="maxHistoryPoints" 
                  min="10" 
                  max="200"
                  @change="updateMaxHistory"
                >
              </label>
            </div>
          </div>
          
          <div class="control-group">
            <h5>🎯 预设位置</h5>
            <div class="preset-buttons">
              <button @click="moveToCenter" class="preset-btn">📍 中心</button>
              <button @click="moveToCorner" class="preset-btn">↖️ 角落</button>
              <button @click="moveRandomly" class="preset-btn">🎲 随机</button>
            </div>
          </div>
        </div>
      </div>
    </div>
    
    <div class="tracker-footer">
      <div class="features">
        <div class="feature-item">
          <span class="feature-icon">📍</span>
          <span>实时位置跟踪</span>
        </div>
        <div class="feature-item">
          <span class="feature-icon">📊</span>
          <span>智能数据分析</span>
        </div>
        <div class="feature-item">
          <span class="feature-icon">📈</span>
          <span>历史轨迹记录</span>
        </div>
        <div class="feature-item">
          <span class="feature-icon">🎯</span>
          <span>象限统计分析</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed, onMounted, onUnmounted } from 'vue'

// 响应式数据
const mouseX = ref<number>(0)
const mouseY = ref<number>(0)
const isTracking = ref<boolean>(false)
const isRecording = ref<boolean>(true)
const showCursor = ref<boolean>(true)
const showMarkers = ref<boolean>(true)
const showGrid = ref<boolean>(true)
const sampleInterval = ref<number>(100)
const maxHistoryPoints = ref<number>(100)

// 历史轨迹数据
interface PositionPoint {
  x: number
  y: number
  time: string
  opacity: number
}

const positionHistory = ref<PositionPoint[]>([])
const lastPosition = ref<{ x: number; y: number; time: number } | null>(null)
const totalDistance = ref<number>(0)
const quadrantCounts = ref<{ [key: string]: number }>({
  '左上': 0,
  '右上': 0,
  '左下': 0,
  '右下': 0
})

// 屏幕尺寸
const screenWidth = ref<number>(window.innerWidth)
const screenHeight = ref<number>(window.innerHeight)

// 跟踪区域尺寸（计算属性）
const trackingAreaSize = computed(() => ({
  width: Math.min(600, screenWidth.value - 100),
  height: Math.min(400, screenHeight.value - 300)
}))

// 计算属性 - 位置百分比
const xPercentage = computed(() => {
  return screenWidth.value > 0 ? (mouseX.value / screenWidth.value) * 100 : 0
})

const yPercentage = computed(() => {
  return screenHeight.value > 0 ? (mouseY.value / screenHeight.value) * 100 : 0
})

// 计算属性 - 相对位置（相对于跟踪区域）
const relativeX = computed(() => {
  return Math.max(0, Math.min(trackingAreaSize.value.width, mouseX.value - 50))
})

const relativeY = computed(() => {
  return Math.max(0, Math.min(trackingAreaSize.value.height, mouseY.value - 200))
})

// 计算属性 - 光标样式
const cursorStyle = computed(() => {
  return {
    left: relativeX.value + 'px',
    top: relativeY.value + 'px',
    display: showCursor.value && isTracking.value ? 'block' : 'none'
  }
})

// 计算属性 - 标记位置
const markerXPosition = computed(() => {
  return Math.max(20, Math.min(trackingAreaSize.value.width - 60, relativeX.value))
})

const markerYPosition = computed(() => {
  return Math.max(20, Math.min(trackingAreaSize.value.height - 40, relativeY.value))
})

// 计算属性 - 距离中心
const distanceFromCenter = computed(() => {
  const centerX = trackingAreaSize.value.width / 2
  const centerY = trackingAreaSize.value.height / 2
  return Math.sqrt(Math.pow(relativeX.value - centerX, 2) + Math.pow(relativeY.value - centerY, 2))
})

// 计算属性 - 当前象限
const currentQuadrant = computed(() => {
  const centerX = trackingAreaSize.value.width / 2
  const centerY = trackingAreaSize.value.height / 2
  
  if (relativeX.value < centerX && relativeY.value < centerY) return '左上'
  if (relativeX.value >= centerX && relativeY.value < centerY) return '右上'
  if (relativeX.value < centerX && relativeY.value >= centerY) return '左下'
  return '右下'
})

// 计算属性 - 象限统计
const quadrantStats = computed(() => quadrantCounts.value)

// 计算属性 - 平均位置
const averagePosition = computed(() => {
  if (positionHistory.value.length === 0) return { x: 0, y: 0 }
  
  const sum = positionHistory.value.reduce((acc, point) => ({
    x: acc.x + point.x,
    y: acc.y + point.y
  }), { x: 0, y: 0 })
  
  return {
    x: sum.x / positionHistory.value.length,
    y: sum.y / positionHistory.value.length
  }
})

// 计算属性 - 移动模式
const movementPattern = computed(() => {
  const total = Object.values(quadrantCounts.value).reduce((sum, count) => sum + count, 0)
  
  if (total === 0) {
    return {
      direction: '暂无数据',
      speed: '暂无数据',
      activity: '暂无数据'
    }
  }
  
  const maxQuadrant = Object.entries(quadrantCounts.value).reduce((max, [key, value]) => 
    value > max.count ? { key, count: value } : max, { key: '', count: 0 }
  )
  
  const avgSpeed = averageSpeed.value
  let speedLevel = '慢速'
  if (avgSpeed > 200) speedLevel = '快速'
  else if (avgSpeed > 100) speedLevel = '中速'
  
  let activityLevel = '低活跃'
  if (total > 50) activityLevel = '高活跃'
  else if (total > 20) activityLevel = '中活跃'
  
  return {
    direction: maxQuadrant.key || '均匀分布',
    speed: speedLevel,
    activity: activityLevel
  }
})

// 计算属性 - 速度分析
const currentSpeed = computed(() => {
  if (!lastPosition.value) return 0
  const now = Date.now()
  const timeDiff = (now - lastPosition.value.time) / 1000
  if (timeDiff === 0) return 0
  
  const distance = Math.sqrt(
    Math.pow(mouseX.value - lastPosition.value.x, 2) + 
    Math.pow(mouseY.value - lastPosition.value.y, 2)
  )
  
  return distance / timeDiff
})

const averageSpeed = computed(() => {
  if (positionHistory.value.length < 2) return 0
  
  const totalTime = 10 // 假设10秒内的平均速度
  return totalDistance.value / totalTime
})

const maxSpeed = computed(() => {
  // 简化实现，返回当前速度的1.5倍作为估算最大值
  return currentSpeed.value * 1.5
})

// 方法 - 鼠标事件处理
const handleMouseMove = (event: MouseEvent) => {
  mouseX.value = event.clientX
  mouseY.value = event.clientY
  
  if (isRecording.value && isTracking.value) {
    updatePositionHistory()
    updateMovementStats()
  }
}

const handleMouseEnter = () => {
  isTracking.value = true
  console.log('🖱️ 鼠标进入跟踪区域')
}

const handleMouseLeave = () => {
  isTracking.value = false
  console.log('🖱️ 鼠标离开跟踪区域')
}

// 方法 - 更新位置历史
const updatePositionHistory = () => {
  if (!isRecording.value) return
  
  const now = new Date()
  const timeString = now.toLocaleTimeString('zh-CN', { 
    hour: '2-digit', 
    minute: '2-digit', 
    second: '2-digit' 
  })
  
  // 计算透明度（越新的点越亮）
  const opacity = Math.max(0.1, 1 - (positionHistory.value.length / maxHistoryPoints.value))
  
  positionHistory.value.unshift({
    x: relativeX.value,
    y: relativeY.value,
    time: timeString,
    opacity
  })
  
  // 限制历史记录数量
  if (positionHistory.value.length > maxHistoryPoints.value) {
    positionHistory.value = positionHistory.value.slice(0, maxHistoryPoints.value)
  }
  
  // 更新最后位置
  if (lastPosition.value) {
    const distance = Math.sqrt(
      Math.pow(mouseX.value - lastPosition.value.x, 2) + 
      Math.pow(mouseY.value - lastPosition.value.y, 2)
    )
    totalDistance.value += distance
  }
  
  lastPosition.value = {
    x: mouseX.value,
    y: mouseY.value,
    time: Date.now()
  }
}

// 方法 - 更新移动统计
const updateMovementStats = () => {
  // 更新象限统计
  quadrantCounts.value[currentQuadrant.value]++
}

// 方法 - 获取象限百分比
const getQuadrantPercentage = (count: number) => {
  const total = Object.values(quadrantCounts.value).reduce((sum, c) => sum + c, 0)
  return total === 0 ? 0 : (count / total) * 100
}

// 方法 - 控制功能
const clearHistory = () => {
  positionHistory.value = []
  totalDistance.value = 0
  quadrantCounts.value = {
    '左上': 0,
    '右上': 0,
    '左下': 0,
    '右下': 0
  }
  console.log('🗑️ 历史轨迹已清空')
}

const toggleRecording = () => {
  isRecording.value = !isRecording.value
  console.log(isRecording.value ? '📹 开始记录轨迹' : '⏸️ 暂停记录轨迹')
}

const toggleShowCursor = () => {
  showCursor.value = !showCursor.value
  console.log(showCursor.value ? '👁️ 显示鼠标光标' : '🙈 隐藏鼠标光标')
}

const toggleShowMarkers = () => {
  showMarkers.value = !showMarkers.value
  console.log(showMarkers.value ? '📍 显示位置标记' : '🙈 隐藏位置标记')
}

const toggleShowGrid = () => {
  showGrid.value = !showGrid.value
  console.log(showGrid.value ? '🔲 显示网格' : '🙈 隐藏网格')
}

const updateSampleInterval = () => {
  console.log(`⏱️ 采样间隔更新为: ${sampleInterval.value}ms`)
}

const updateMaxHistory = () => {
  console.log(`📊 历史记录上限更新为: ${maxHistoryPoints.value}`)
  // 如果当前历史记录超过新上限，进行裁剪
  if (positionHistory.value.length > maxHistoryPoints.value) {
    positionHistory.value = positionHistory.value.slice(0, maxHistoryPoints.value)
  }
}

// 方法 - 预设位置（模拟功能）
const moveToCenter = () => {
  console.log('📍 移动到中心位置')
  // 这里可以添加实际的鼠标移动逻辑（需要浏览器API支持）
}

const moveToCorner = () => {
  console.log('↖️ 移动到角落位置')
}

const moveRandomly = () => {
  console.log('🎲 随机移动位置')
}

// 生命周期
onMounted(() => {
  console.log('🖱️ 鼠标位置监听器已启动')
  
  // 监听窗口大小变化
  window.addEventListener('resize', () => {
    screenWidth.value = window.innerWidth
    screenHeight.value = window.innerHeight
  })
  
  // 监听全局鼠标移动（用于显示全局坐标）
  window.addEventListener('mousemove', (event) => {
    // 更新全局坐标，但不记录历史
    mouseX.value = event.clientX
    mouseY.value = event.clientY
  })
})

onUnmounted(() => {
  console.log('🖱️ 鼠标位置监听器已停止')
})
</script>

<style scoped>
.mouse-tracker {
  max-width: 1200px;
  margin: 30px auto;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 20px;
  padding: 30px;
  color: white;
  font-family: 'Arial', sans-serif;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
}

.tracker-header {
  text-align: center;
  margin-bottom: 30px;
}

.tracker-header h2 {
  font-size: 28px;
  margin-bottom: 10px;
  background: linear-gradient(45deg, #fff, #42b883);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  opacity: 0.8;
  font-size: 16px;
}

.tracker-body {
  display: flex;
  flex-direction: column;
  gap: 25px;
}

.position-display {
  background: rgba(255, 255, 255, 0.1);
  padding: 25px;
  border-radius: 15px;
}

.position-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.position-card {
  background: rgba(255, 255, 255, 0.05);
  padding: 20px;
  border-radius: 12px;
  text-align: center;
  border-left: 4px solid transparent;
}

.position-card.x-position {
  border-left-color: #007bff;
}

.position-card.y-position {
  border-left-color: #28a745;
}

.position-icon {
  font-size: 24px;
  margin-bottom: 10px;
}

.position-value {
  font-size: 32px;
  font-weight: bold;
  margin-bottom: 5px;
  color: #42b883;
}

.position-label {
  font-size: 14px;
  opacity: 0.8;
  margin-bottom: 15px;
}

.position-bar {
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
}

.position-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
}

.x-position .position-fill {
  background: #007bff;
}

.y-position .position-fill {
  background: #28a745;
}

.position-summary {
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: rgba(255, 255, 255, 0.05);
  padding: 15px;
  border-radius: 10px;
}

.summary-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.summary-icon {
  font-size: 16px;
}

.tracking-area {
  position: relative;
  width: 100%;
  height: 400px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 15px;
  overflow: hidden;
  cursor: crosshair;
  border: 2px dashed rgba(255, 255, 255, 0.2);
}

.area-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  background: rgba(255, 255, 255, 0.1);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.area-header h3 {
  margin: 0;
  color: #42b883;
  font-size: 16px;
}

.area-status {
  padding: 5px 10px;
  border-radius: 15px;
  font-size: 12px;
  font-weight: bold;
  transition: all 0.3s ease;
}

.area-status.active {
  background: rgba(40, 167, 69, 0.3);
  color: #28a745;
}

.area-status:not(.active) {
  background: rgba(220, 53, 69, 0.3);
  color: #dc3545;
}

.mouse-cursor {
  position: absolute;
  width: 20px;
  height: 20px;
  pointer-events: none;
  z-index: 10;
  transition: all 0.1s ease;
}

.cursor-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  background: #42b883;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 10px rgba(66, 184, 131, 0.8);
}

.cursor-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  border: 2px solid #42b883;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1.5); opacity: 0; }
}

.area-grid {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
}

.grid-lines {
  position: absolute;
  background: rgba(255, 255, 255, 0.1);
}

.grid-lines.horizontal {
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  transform: translateY(-50%);
}

.grid-lines.vertical {
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  transform: translateX(-50%);
}

.grid-center {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  background: #42b883;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.position-markers {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
}

.marker-x, .marker-y {
  position: absolute;
  pointer-events: none;
}

.marker-line {
  background: rgba(255, 255, 255, 0.3);
}

.marker-x .marker-line {
  width: 100%;
  height: 1px;
  position: absolute;
  top: 0;
  left: 0;
}

.marker-y .marker-line {
  width: 1px;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

.marker-label {
  position: absolute;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  white-space: nowrap;
}

.marker-x .marker-label {
  top: -20px;
  left: 10px;
}

.marker-y .marker-label {
  left: 10px;
  top: -20px;
}

.tracking-info {
  position: absolute;
  bottom: 15px;
  left: 15px;
  background: rgba(0, 0, 0, 0.8);
  padding: 10px 15px;
  border-radius: 8px;
  font-size: 12px;
  backdrop-filter: blur(10px);
}

.info-item {
  display: flex;
  justify-content: space-between;
  gap: 15px;
  margin-bottom: 5px;
}

.info-item:last-child {
  margin-bottom: 0;
}

.info-label {
  opacity: 0.8;
}

.info-value {
  color: #42b883;
  font-weight: bold;
}

.history-section {
  background: rgba(255, 255, 255, 0.1);
  padding: 25px;
  border-radius: 15px;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.history-header h4 {
  margin: 0;
  color: #42b883;
  font-size: 16px;
}

.history-controls {
  display: flex;
  gap: 10px;
}

.clear-btn, .record-btn {
  padding: 8px 12px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.3s ease;
}

.clear-btn {
  background: rgba(220, 53, 69, 0.3);
  color: #dc3545;
}

.clear-btn:hover {
  background: rgba(220, 53, 69, 0.5);
}

.record-btn {
  background: rgba(40, 167, 69, 0.3);
  color: #28a745;
}

.record-btn.recording {
  background: rgba(40, 167, 69, 0.5);
}

.record-btn:hover {
  background: rgba(40, 167, 69, 0.5);
}

.history-canvas {
  position: relative;
  width: 100%;
  height: 200px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 15px;
}

.canvas-grid {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

.history-point {
  position: absolute;
  width: 4px;
  height: 4px;
  pointer-events: none;
}

.point-dot {
  width: 100%;
  height: 100%;
  background: #42b883;
  border-radius: 50%;
  box-shadow: 0 0 4px rgba(66, 184, 131, 0.8);
}

.empty-history {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  opacity: 0.6;
}

.empty-icon {
  font-size: 32px;
  margin-bottom: 10px;
}

.empty-text {
  font-size: 14px;
}

.history-stats {
  display: flex;
  justify-content: space-around;
  background: rgba(255, 255, 255, 0.05);
  padding: 15px;
  border-radius: 8px;
  font-size: 12px;
}

.stats-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.stats-label {
  opacity: 0.7;
}

.stats-value {
  color: #42b883;
  font-weight: bold;
  font-size: 14px;
}

.analysis-section {
  background: rgba(255, 255, 255, 0.1);
  padding: 25px;
  border-radius: 15px;
}

.analysis-section h4 {
  margin-bottom: 20px;
  color: #42b883;
  font-size: 16px;
}

.analysis-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
}

.analysis-card {
  background: rgba(255, 255, 255, 0.05);
  padding: 20px;
  border-radius: 12px;
}

.analysis-card h5 {
  margin-bottom: 15px;
  color: #42b883;
  font-size: 14px;
}

.pattern-item, .quadrant-item, .speed-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 12px;
}

.pattern-item:last-child, .quadrant-item:last-child, .speed-item:last-child {
  margin-bottom: 0;
}

.pattern-label, .quadrant-label, .speed-label {
  opacity: 0.8;
}

.pattern-value, .quadrant-count, .speed-value {
  color: #42b883;
  font-weight: bold;
}

.quadrant-bar {
  flex: 1;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  margin: 0 10px;
  overflow: hidden;
}

.quadrant-fill {
  height: 100%;
  background: #42b883;
  border-radius: 3px;
  transition: width 0.5s ease;
}

.controls-section {
  background: rgba(255, 255, 255, 0.1);
  padding: 25px;
  border-radius: 15px;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
}

.control-group {
  background: rgba(255, 255, 255, 0.05);
  padding: 20px;
  border-radius: 10px;
}

.control-group h5 {
  margin-bottom: 15px;
  color: #42b883;
  font-size: 14px;
}

.control-item {
  margin-bottom: 10px;
  font-size: 12px;
}

.control-item:last-child {
  margin-bottom: 0;
}

.control-item label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.control-item input[type="checkbox"] {
  cursor: pointer;
}

.control-item select, .control-item input[type="number"] {
  padding: 4px 8px;
  border: none;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.9);
  color: #333;
  font-size: 11px;
  margin-left: 8px;
}

.preset-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.preset-btn {
  padding: 6px 10px;
  border: none;
  border-radius: 6px;
  background: rgba(66, 184, 131, 0.3);
  color: #42b883;
  cursor: pointer;
  font-size: 11px;
  transition: all 0.3s ease;
}

.preset-btn:hover {
  background: rgba(66, 184, 131, 0.5);
}

.tracker-footer {
  margin-top: 30px;
  padding-top: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 15px;
}

.feature-item {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  padding: 10px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  font-size: 12px;
}

.feature-icon {
  font-size: 16px;
}

@media (max-width: 768px) {
  .mouse-tracker {
    padding: 20px;
    margin: 20px;
  }
  
  .position-grid {
    grid-template-columns: 1fr;
  }
  
  .position-summary {
    flex-direction: column;
    gap: 10px;
  }
  
  .tracking-area {
    height: 300px;
  }
  
  .history-stats {
    flex-direction: column;
    gap: 10px;
  }
  
  .analysis-grid {
    grid-template-columns: 1fr;
  }
  
  .controls-grid {
    grid-template-columns: 1fr;
  }
}
</style>